$(function(){
    // 添加银行卡
    $(".add").on("click",function(){
        window.location.href="my_addBankCard.html?loginName="+baseFunction.getUrlParameterValueByKey("loginName")+"";
    })
    
    var loginName=baseFunction.getUrlParameterValueByKey("loginName");
    getList(loginName);
})

/**
 * 获取银行卡列表
 */
function getList(loginName){
    $(".loding").show(0);
    var data={
      userName: baseFunction.encryption(loginName)
    };
    baseFunction.netRequest("quickCardBind",data,function(res){
       //解密
      if (res.code==200){
        var data = JSON.parse(JSON.parse(res.data).cards);
        for(var i=0;i<data.length;i++){
          data[i].cardno = (data[i].cardno).slice(-4);
          for (var j = 0; j < bankCard.length;j++){
            if ((data[i].bankName).indexOf(bankCard[j].bankName)!=-1){
              data[i].bg = "../static/img/" + bankCard[j].bankBackground + "@2x.png";
              data[i].bg2 = "../static/img/" + bankCard[j].bigLogo + ".png"
            }
          }
        }
        console.log(data);
        var html="";
        for(var i=0;i<data.length;i++){
            var bankType=data[i].cardType==2?"信用卡":"借记卡";
            html+="<div class='li' data_id='"+data[i].id+"'>"
                +"<img class='bg' src='"+data[i].bg+"'/>"
                +"<div class='left fl'>"
                +"<img src='"+data[i].bg2+"'/>"
                +"</div>"
                +"<div class='right'>"
                +"<div class='cardName'>"
                +"<p>"+data[i].bankName+"</p>"
                +"<p class='p2'>"+bankType+"</p>"
                +"</div>"
                +"<div class='cardNum'>"
                +"<div>****</div>"
                +"<div>****</div>"
                +"<div>****</div>"
                +"<div>"+data[i].cardno+"</div>"
                +"</div>"
                +"</div>"
                +"</div>"
        }
        $(".content").html(html);
        $(".loding").hide(0);
        // 查看银行卡详情
      $(".content").on("click",".li",function(){
        var id=$(this).attr("data_id");
        window.location.href="my_modifyCreditCard.html?loginName=" +loginName+ "&id="+id+"";
      })
      }else{
        $(".prompt").html(res.message).show(0).delay(1000).hide(0);
      }
    })
}